package com.zhufeng.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.zhufeng.base.api.ShowUserApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: RestUserController
 * @Description TODO
 * @author 月夜烛峰
 * @date 2022/8/30 09:55
 */
@Slf4j
@RestController
public class RestUserController{

    @Autowired
    ShowUserApi showUserApi;

@RequestMapping("/fegin/{id}")
public JSONObject showUserInfo(@PathVariable("id") int id) {
    log.info("接收到feign请求，id:"+id);
    JSONObject userJson = new JSONObject();
    userJson.put("status", "success");
    userJson.put("name","zhufeng");
//    try {
//        for(int i=9;i>0;i--){
//            log.info("请求等待中..."+i);
//            Thread.sleep(1000);
//        }
//    } catch (InterruptedException e) {
//        log.error("服务超时,",e);
//    }
    return userJson;
}

    @RequestMapping("/user/{id}")
    public JSONObject showUserById(@PathVariable("id") int id) {
        log.info("请求参数id:"+id);
        return showUserApi.showUserById(id);
    }

    @RequestMapping("user")
    public String showUser(@RequestBody Object reqParam) {
        log.info("请求参数:"+reqParam);
        JSONObject userJson = new JSONObject();
        userJson.put("status", "success");
        //8081端口时改为以下信息
        userJson.put("msg", "hello world!");
        //8082端口时改为以下信息
        //userJson.put("msg", "good luck~");
        userJson.put("name","zhufeng");
        return userJson.toJSONString();
    }
}
